#include <iostream>
#include <algorithm>

int n, m;
int ps[1000007];
std::string s;
constexpr int inf = 0x3b9aca00;

struct matrix {
  int x[3][3];
  int* operator[](int i) { return x[i]; }
  matrix operator*(matrix& rhs) {
    matrix ans;
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        ans[i][j] = -inf;
      }
    }
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        if (x[i][j] != -inf) {
          for (int k = 0; k < 3; ++k) {
            if (rhs[j][k] != -inf) {
              ans[i][k] = std::max(ans[i][k], x[i][j] + rhs[j][k]);
            }
          }
        }
      }
    }
    return ans;
  }
};
struct vector {
  int x[3];
  int& operator[](int i) { return x[i]; }
  vector operator*(matrix& rhs) {
    vector ans;
    for (int i = 0; i < 3; ++i) {
      ans[i] = -inf;
    }
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        ans[j] = std::max(ans[j], x[i] + rhs[i][j]);
      }
    }
    return ans;
  }
};

matrix dat[2000007];
int ls[2000007], rs[2000007], nodecnt;
int build(int l, int r) {
  int p = ++nodecnt, mid = (l + r) >> 1;
  if (l == r) {
    if (s[mid - 1] == '0') {
      dat[p][0][0] = -1, dat[p][0][1] = -inf, dat[p][0][2] = -inf;
      dat[p][1][0] = -inf, dat[p][1][1] = 0, dat[p][1][2] = -inf;
      dat[p][2][0] = 0, dat[p][2][1] = -inf, dat[p][2][2] = 0;
    } else {
      dat[p][0][0] = 1, dat[p][0][1] = 1, dat[p][0][2] = -inf;
      dat[p][1][0] = -inf, dat[p][1][1] = 0, dat[p][1][2] = -inf;
      dat[p][2][0] = -inf, dat[p][2][1] = -inf, dat[p][2][2] = 0;
    }
    return p;
  }
  ls[p] = build(l, mid), rs[p] = build(mid + 1, r);
  dat[p] = dat[ls[p]] * dat[rs[p]];
  return p;
}
void query(int p, int l, int r, int ql, int qr, vector& t) {
  if (ql <= l && r <= qr) {
    t = t * dat[p];
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) {
    query(ls[p], l, mid, ql, qr, t);
  }
  if (qr > mid) {
    query(rs[p], mid + 1, r, ql, qr, t);
  }
}

int main() {
  std::freopen("good.in", "r", stdin);
  std::freopen("good.out", "w", stdout);
  std::cin.tie(nullptr)->sync_with_stdio(false);
  std::cin >> n >> m >> s;
  for (int i = 1; i <= n; ++i) {
    ps[i] = ps[i - 1] + ((s[i - 1] == '1') ? +1 : -1);
  }
  int root = build(1, n), res = 0;
  while (m--) {
    int l, r;
    std::cin >> l >> r;
    if (ps[r] - ps[l - 1] == -(r - l + 1)) {
      res ^= (r - l + 2);
      continue;
    }
    vector ans;
    ans[0] = 0, ans[1] = 0, ans[2] = 0;
    query(root, 1, n, l, r, ans);
    int op = ans[0], h = ans[1];
    res ^= ((op - (ps[r] - ps[l - 1])) + (h - op));
  }
  std::cout << res << '\n';
  return 0;
}